﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Entity;

namespace School.SystemManage.WebPages.UserManage
{
    public partial class PwdChange : BasePage
    {
        TechnologySchoolEntities db = new TechnologySchoolEntities();

        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            try
            {
                int uid = int.Parse(GetCookie("UserLoginID"));
                var currentUser = db.AdminUsers.FirstOrDefault(u => u.UserID == uid);
                if (currentUser != null)
                {
                    currentUser.UserPwd = Security.Cryptography.AESEncrypt(newPwd.Text.Trim(), "technology");
                    db.SaveChanges();

                    lblMsg.Text = "修改成功！";
                }
                else
                {
                    lblMsg.Text = "用户不存在！";
                }
            }
            catch (Exception ex)
            {
                lblMsg.Text = "修改密码发生异常,原因：" + ex.Message;
            }
        }
    }
}
